package org.example.controller;



import org.example.dto.AddSpuDto;
import org.example.dto.EditSpuDto;
import org.example.entity.SysSpu;
import org.example.entity.SysUser;
import org.example.model.PageBean;
import org.example.service.SysSpuService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;


@RestController
@RequestMapping("/spu")
public class SysSpuController {

    @Resource
    private SysSpuService sysSpuService;

    //渲染数据
    @GetMapping
    public PageBean<SysSpu> getAll(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "5") Integer size) {

        return sysSpuService.getAll(page,size);
    }

    //删除
    @DeleteMapping("/{id}")
    public String deleteById(@PathVariable("id") Integer id) {
        sysSpuService.deleteById(id);
        return "success";
    }

    //添加数据
    @PostMapping
    public String addSpu(@RequestBody AddSpuDto addSpuDto) {
        System.out.println(addSpuDto);
        sysSpuService.addSpu(addSpuDto);
        return "success";
    }

    //获取id回显
    @GetMapping("/{id}")
    public EditSpuDto getSpuById(@PathVariable("id") Integer id) {
        EditSpuDto editSpu = sysSpuService.getById(id);
        return editSpu;
    }

    //编辑数据
    @PutMapping
    public String update(@RequestBody EditSpuDto editSpuDto) {
        sysSpuService.editSpu(editSpuDto);
        System.out.println("修改");
        System.out.println(editSpuDto);
        return "success";
    }
}
